//
//  LandmarkList.swift
//  ChinaLandmark
//
//  Created by liy on 2025/2/9.
//

import SwiftUI

struct LandmarkList: View {
  @State private var showFavoriteOnly = false
  @EnvironmentObject var userData: UserData

  var body: some View {
    NavigationView {
      List {
        Toggle(isOn: $showFavoriteOnly) {
          Text("只展示收藏")
        }
        ForEach(userData.userLandmarks) { landmark in

          // 使用逻辑或 方式
          if !self.showFavoriteOnly || landmark.isFavorite {
            NavigationLink(destination: LandmarkDetail(landmark: landmark).environmentObject(self.userData)) {
              LandmarkCell(landmark: landmark)
            }
          }
        }
      }
      .navigationTitle(Text("中国地标"))
      .navigationBarTitleDisplayMode(.large)
      .listStyle(.plain)
    }
  }
}

#Preview {
  NavigationView {
    LandmarkList()
  }
  .environmentObject(UserData())
}
